﻿
// 2023/2/28: 首个版本
// 2023/7/6: receive输出NV12
// 2023/7/11: 合并Generic/Special。增加方法getHardwareDevice，receiveHardwareFrame
// 2023/7/12: 使用CompatibleImage::isValid
// 2023/7/12: open方法增加size参数。支持输出QSV格式AVFrame。receiveHardwareFrame输出time
// 2023/7/18: 支持VAAPI-MJPEG
// 2023/8/2: 兼容旧版FFMPEGDL
// 2023/8/24: av_hwdevice_ctx_create加锁
// 2023/10/9: 添加英文注释
// 2024/6/12: 支持spadas9
// 2024/6/19: 增加downloadHardwareFrame
// 2024/11/11: 增加getHardwareCreateLocks

#ifndef GPU_DECODER_H_
#define GPU_DECODER_H_

#include "ffmpegdl.h"
#include "NextCompatibleImage.h"

namespace videonext
{
	using namespace spadas;

	class GPUDecoder : public Object<class GPUDecoderVars>
	{
	public:
		GPUDecoder();
		Bool open(Enum<VideoDataCodec> codec, AVHWDeviceType type, Size2D size);
		void close();
		Pointer getHardwareDevice();
		Bool send(Binary packetData, Double time);
		void flush();
		// output: new AVFrameNV12 or AVFrameYUV420P
		Bool receive(CompatibleImage& image, Double& time);
		Bool receiveHardwareFrame(Pointer& hardwareFrame, Double& time);
		Bool downloadHardwareFrame(Pointer hardwareFrame, CompatibleImage& image, Bool releaseHardwareFrame);
		static Array<Lock> getHardwareCreateLocks();
	};
}

#endif
